<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *智能体
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'待审核图片'),
);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$params['logo like']='%images/checkimg.jpg%';
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_aiagent_useragent',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$imgid=explode('.jpg?',$item['logo']);
			if($imgid[1]){
				$attachment=pdo_get('core_attachment',array('id'=>$imgid[1],'uniacid'=>$_SESSION['uniacid']));
				$item['checkimglogo']=$attachment['attachment'];
				$item['oldlogo']=$attachment['old'];
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$tips='这里是平台智能体明白，用户的智能体不在这里展示！';
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>$tips,'edit'=>false,'del_one'=>true,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'id','title'=>'ID','type'=>'string'),
			array('name'=>'title','title'=>'智能体名称','type'=>'string'),
			array('name'=>'checkimglogo','title'=>'待审核图片','type'=>'image'),
			array('name'=>'oldlogo','title'=>'原图片','type'=>'image'),
		),'action'=>array(
			array('type'=>'post','op'=>'check1','title'=>'审核通过'),
			array('type'=>'post','op'=>'check2','title'=>'审核不通过'),
		),'batch'=>array(
			array('type'=>'post','url'=>'check1','title'=>'一键审核通过'),
			array('type'=>'post','url'=>'check2','title'=>'一键审核不通过'),
		)),
		'search'=>array(
			array('name'=>'title','width'=>15,'title'=>'智能体名称','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	$return['isfen']=array('不支持','支持');
	exi($return);
}
if($_RQ['op']=='check1'){
	$ids=trim($_RQ['ids'],';');
	if($ids){
		$ids=explode(';',$ids);
	}else{
		$ids=array();
	}
	if($_RQ['id']){
		$ids[]=$_RQ['id'];
	}
	if(count($ids)==0){
		exi('请先选择智能体','error');
	}
	foreach($ids as $id){
		$id=intval($id);
		if($id){
			$agent=pdo_get('jy_aiagent_useragent',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			$imgid=explode('.jpg?',$agent['logo']);
			if($imgid[1]){
				$attachment=pdo_get('core_attachment',array('id'=>$imgid[1],'uniacid'=>$_SESSION['uniacid']));
				$agent['checkimglogo']=$attachment['attachment'];
				$agent['oldlogo']=$attachment['old'];
			}
			pdo_update('jy_aiagent_useragent',array('logo'=>$agent['checkimglogo']),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('操作成功！');
}
if($_RQ['op']=='check2'){
	$ids=trim($_RQ['ids'],';');
	if($ids){
		$ids=explode(';',$ids);
	}else{
		$ids=array();
	}
	if($_RQ['id']){
		$ids[]=$_RQ['id'];
	}
	if(count($ids)==0){
		exi('请先选择智能体','error');
	}
	foreach($ids as $id){
		$id=intval($id);
		if($id){
			$agent=pdo_get('jy_aiagent_useragent',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			$imgid=explode('.jpg?',$agent['logo']);
			if($imgid[1]){
				$attachment=pdo_get('core_attachment',array('id'=>$imgid[1],'uniacid'=>$_SESSION['uniacid']));
				$agent['checkimglogo']=$attachment['attachment'];
				$agent['oldlogo']=$attachment['old'];
			}
			pdo_update('jy_aiagent_useragent',array('logo'=>$agent['oldlogo']),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('操作成功！图片审核不通过，已恢复原图片！');
}